package com.hxzy.common;

import com.github.pagehelper.PageInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * 用于返回状态信息
 * @Description:
 * @Author: ykj
 * @Date: 2022/2/26 16:33
 */
public class ResultAjax extends HashMap<String,Object> {
    public final static String CODE="code";
    public final static String MESSAGE="message";
    public final static String DATA="data";


    public static ResultAjax success(){
        return  ResultAjax.success("ok");
    }

    public static ResultAjax success(String message){
        ResultAjax rj=new ResultAjax();
        rj.put(CODE, 0);
        rj.put(MESSAGE, message);
        return rj;
    }

    public static ResultAjax succss_data(Object data){
        ResultAjax rj = new ResultAjax();
        rj.put(CODE, 0);
        rj.put(MESSAGE, "ok");
        rj.put(DATA, data);
        return rj;
    }

    public static ResultAjax error(){
        return ResultAjax.error(500,"操作失败");
    }

    public static ResultAjax error(String message){
        return ResultAjax.error(501,message);
    }

    public static ResultAjax error(int code,String message){
        ResultAjax rj=new ResultAjax();
        rj.put(CODE,code );
        rj.put(MESSAGE, message);
        return rj;
    }

    /**
     *分页数据
     * @param pageInfo
     * return
     */
    public static ResultAjax success_page(PageInfo pageInfo){
        ResultAjax rj=new ResultAjax();
        rj.put(CODE, 0);
        rj.put(MESSAGE, "ok");

        Map<String,Object> dataMap=new HashMap<>();
        System.out.println(pageInfo);
        dataMap.put("rows", pageInfo.getList());
        dataMap.put("total", pageInfo.getTotal());

        rj.put(DATA, dataMap);
        return rj;
    }

}
